﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using COM.OA.BLL;
using System.Collections.Generic;
using COM.OA.Entity;
using System.Data.SqlClient;

public partial class deletegroup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //取群ID
        string qid = this.Request["qunid"];
        //判断 群ID是否存在 不存在则跳回qunzu.aspx
        if (qid != null)
        {
            //取用户ID
            string id = this.Request["u_id"];
            //判断用户是否为空，如果为空证明是第一次初始化，则显示该组成员。如果不为空则是2次加载，用于删除成员。
            if (id != null)
            {
                //把string类型转换成int 
                int idd = Int32.Parse(id);
                string where = "u_id='{0}'";
                where = string.Format(where, idd);
                //查询该用户信息
                IList<users> ulist = usersBLL.Select(where);
                //用实体类接受该用户
                if (ulist.Count != 0)
                {
                    //取出用户信息 修改其群组属性，默认1为NULL无群组
                    users uu = ulist[0];
                    uu.u_g_id = 1;
                    usersBLL.Update(uu);
                    id = null;
                    this.Response.Write(string.Format(GetRedirect.REDIRECT, "deletechengyuan.aspx?qunid=" + qid));
                }
                else
                {
                    this.Response.Write(string.Format(GetRedirect.WINALERT,"该用户不存在"));
                }
            }
            else
            {
                //根据群组ID 查出群内所有成员
                //string qid = this.Request.Form["Hidqunid"];
                int qunid = Int32.Parse(qid);
                //存储过程传参 必调类
                SqlParameter parambumen = new SqlParameter("@u_g_id", qunid);
                //调用存储过程并用 集合 接收
                IList<qunzuchengyuan> lists = BLLGeneric.Select<qunzuchengyuan>(CommandType.StoredProcedure, "qunzuchengyuan", parambumen);
                //设置GRIDVIEW数据源
                this.Gidv_qunchengyuan.DataSource = lists;
                //qunzuchengyuan gg = lists[0];

                //this.Gidv_qunchengyuan
                //进行绑定
                this.Gidv_qunchengyuan.DataBind();

            }
        }
            //如果取不到群组ID则跳回qunzu.aspx
        else
        {
            this.Response.Write(string.Format(GetRedirect.REDIRECT,"qunzu.aspx"));

        }
    }
}
